#include<stdio.h>
#include<algorithm>
int nc;
int np;
int coupons[100000];
int products[100000];
int main(){
    scanf("%d",&nc);
    int i=0;
    while(i<nc){
        scanf("%d",&coupons[i++]);
    }
    std::sort(coupons,coupons+nc);
    scanf("%d",&np);
    i=0;
    while(i<np){
        scanf("%d",&products[i++]);
    }
    std::sort(products,products+np);

    //for(int i=0;i<nc;i++){
    //    printf("%d ",coupons[i]);
    //}
    //printf("\n");
    //for(int i=0;i<np;i++){
    //    printf("%d ",products[i]);
    //}
    //printf("\n");


    int res=0;
    i=0;
    int j=0;
    while(i<nc&&j<np&&coupons[i]<0&&products[j]<0){
        res+=coupons[i]*products[j];
        i++;
        j++;
    }
    //printf("%d\n",res);
    i=nc-1;j=np-1;
    while(i>=0&&j>=0&&coupons[i]>0&&products[j]>0){
        res+=coupons[i]*products[j];
        i--;
        j--;
    }
    printf("%d",res);
    return 0;
}
